package murraco.controller;

import murraco.common.Result;
import murraco.dto.BicycleDto;
import murraco.security.MyUserDetail;
import murraco.service.BicycleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bicycles")
@CrossOrigin
public class BicycleController {

    @Autowired
    private BicycleService bicycleService;

    @PutMapping("/borrow")
    public Result borrowBicycle(@RequestBody BicycleDto bicycleDto, @AuthenticationPrincipal MyUserDetail userDetail){
        return Result.success( bicycleService.borrowBicycle(bicycleDto.getPileNum(),userDetail.getUserId()));
    }

    @PutMapping("/return")
    public Result returnBicycle(@RequestBody BicycleDto bicycleDto,@AuthenticationPrincipal MyUserDetail userDetail){
        bicycleService.returnBicycle(bicycleDto.getBicycleNum(),bicycleDto.getPileNum(),userDetail.getUserId());
        return Result.success();
    }
}
